package com.example.androidaudiovideodemo.activity

import android.graphics.BitmapFactory
import android.graphics.Color
import android.graphics.Paint
import android.view.SurfaceHolder
import com.example.androidaudiovideodemo.R
import com.example.androidaudiovideodemo.base.BaseActivity
import kotlinx.android.synthetic.main.activity_draw_image_by_three_ways.*

/**
 *
 * author: renbing
 *
 * date: 2021/12/9
 *
 * des:1. 在 Android 平台绘制一张图片，使用至少 3 种不同的 API，ImageView，SurfaceView，自定义 View
 */
class DrawImageByThreeWayActivity : BaseActivity(){

    override fun getLayoutId(): Int = R.layout.activity_draw_image_by_three_ways

    override fun performInit() {
        super.performInit()

        setStatusBarColor(this,true)
    }

    override fun initData() {
        super.initData()

        task_one_title_view.setLeftIconColorFilter(Color.BLACK)
        task_one_title_view.setOnLeftIconClickListener {
            finish()
        }

        api_image_view.setImageDrawable(resources.getDrawable(R.mipmap.test_iv,null))

        api_surface_view.holder.addCallback(object : SurfaceHolder.Callback{
            override fun surfaceCreated(holder: SurfaceHolder) {
                val paint = Paint().apply {
                    isAntiAlias = true
                    style = Paint.Style.STROKE
                }
                val bitmap = BitmapFactory.decodeResource(resources, R.mipmap.test_iv)
                val canvas = holder.lockCanvas()
                canvas.drawBitmap(bitmap,0f,0f,paint)
                holder.unlockCanvasAndPost(canvas)
            }

            override fun surfaceChanged(
                holder: SurfaceHolder,
                format: Int,
                width: Int,
                height: Int
            ) {

            }

            override fun surfaceDestroyed(holder: SurfaceHolder) {

            }

        })
    }
}